import { useUserStore } from "@/store";

export const tokenKey = 'token';
export const snKey = 'sn';
export const userKey = 'user_info';
export const uidKey = 'uid';

function getToken() {
	return uni.getStorageSync(tokenKey);
}

function setToken(token: string) {
	uni.setStorageSync(tokenKey, token);
}

function removeToken() {
	uni.removeStorageSync(tokenKey);
}

function getSn() {
	return uni.getStorageSync(snKey);
}

function setSn(sn: string) {
	uni.setStorageSync(snKey, sn);
}

function removeSn() {
	uni.removeStorageSync(snKey);
}

function removeAll() {
	uni.clearStorage()
}

function getUser() {
	return uni.getStorageSync(userKey);
}

function setUser(user: any) {
	uni.setStorageSync(userKey, user);
}

function removeUser() {
	uni.removeStorageSync(userKey);
}
function getUid() {
	return uni.getStorageSync(uidKey);

}
function setUid(uid:number) {
	uni.setStorageSync(uidKey, uid);
}
function removeUid() {
	uni.removeStorageSync(uidKey);
}

function asyncLocalData() {
	const userStore = useUserStore();
	const sn = getSn();
	const user = getUser();
	const token = getToken();
	userStore.setSn(sn);
	userStore.setToken(token);
	userStore.setUserInfo(user);
}
export {
	getToken,
	setToken,
	removeToken,
	getSn,
	setSn,
	removeSn,
	removeAll,
	getUser,
	setUser,
	removeUser,
	getUid,
	setUid,
	removeUid,
	asyncLocalData
};